<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DescargarInscripcion PDF
 *
 * @author MFerreira
 * 
 *  @export-metadata RequiredRoles:ROLE_STUDENT
 * @export Modules
 */
class DescargarInscripcionPDF extends Module {

    public function index() {
        $this->assign("action", $this->route->action("DescargarPDF"));
        $this->display("index");
    }

    public function DescargarPDF() {
        $numeroDocumento = $this->request->get("NumeroDocumento");

        $path = JPATH_ROOT . DS . "tmp" . DS . "com_acaweb" . DS;
        $fileName = md5($numeroDocumento . ModulesContext::instance()->getConfig()->get("periodoActual")) . ".xfdf";

        $file = $path . $fileName;
        $formFile = $path . "Formulario.pdf";

        if (is_file($file)) {
            //TODO: [debug] Borrar esta linea.
//            echo '"C:\wamp\bin\pdftk\pdftk" "' . $formFile . '" fill_form "' . $file . '" output - flatten';
            header('Content-type: application/pdf');
            header('Content-Disposition: attachment; filename="FormularioDiligenciado_' . $numeroDocumento .'.pdf"');
            passthru('"C:\wamp\bin\pdftk\pdftk" "' . $formFile . '" fill_form "' . $file . '" output - flatten');
            exit;
        } else {
            $this->addMessage(new Message("Tu documento de identidad no aparece inscrito en este periodo acad&eacute;mico.", "No encontrado: ", Message::ERROR));
            $this->index();
        }
    }

}

?>
